package chatin.admin;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionsGuardian {

    private static ConnectionsGuardian guardian;

    private Connection con = null;

    private ConnectionsGuardian() {
        try {
            Class.forName("org.postgresql.Driver");
            System.out.println("Conectando com o banco");
        } catch (ClassNotFoundException e) {
            System.out.println("Houve erro na conexão com o SGBD");
            e.printStackTrace();
        }
        try {
            this.con = DriverManager.getConnection("jdbc:postgresql://localhost/chatin", "postgres", "admin");
        } catch (SQLException eCon) {
            System.out.println("Houve erro na conexão com o banco de dados");
            eCon.printStackTrace();
        }
    }

    public static ConnectionsGuardian getConnectionsGuardian() {
        if(guardian==null) {
            guardian = new ConnectionsGuardian();
        }
        return guardian;
    }

    public Connection getConnection() {
        return con;
    }

}
